<?php

function SetSystemTimeByMenu($in_array)
{
	$command_string = "/usr/sbin/date -s ". 
			$in_array['year'].'-'.  $in_array['month'].'-'. $in_array['day']. ';'. 
			'/usr/sbin/date -s '.
			$in_array['hour'].':'. $in_array['min']. ':'.  $in_array['sec']. ";/sbin/hwclock -w ;";
	//print $command_string;
	shell_exec ($command_string);
}

include_once "function_base_xml_class.php";
class CNetTime
{
	private $root_path = "/MINI/SYSSTATUS/TIME";
	private $node_name = "NETTIME";
	private $key_array = array("Enabled", "ServerAddress");
	function GetXmlItem()
	{
		$net= new base_xml_class($this->root_path, $this->node_name, $this->key_array);
		$ret = $net->get_list();
		return $ret[0];
	}
	function EditItem($in_array)
	{
		$net = new base_xml_class($this->root_path, $this->node_name, $this->key_array);
		$net ->edit_item_by_num(0, $in_array);
		$this->Apply();
	}
	function Apply()
	{
		$ret = $this->GetXmlItem();
		$command_read = '/bin/sed \'/ntpdate/d\' /var/spool/cron/crontabs/root > /var/spool/cron/crontabs/root.tmp ; /bin/cp /var/spool/cron/crontabs/root.tmp /var/spool/cron/crontabs/root; ';
		if ($ret['Enabled'] == 1){
			$command = 'echo "50 * * * * /usr/sbin/ntpdate '. $ret['ServerAddress']. '" >> /var/spool/cron/crontabs/root';
		}
		else{
			$command = "";
		}
		shell_exec($command_read. $command);
	}
}

?>
